package com.yhj.reggie.mapper;

import com.yhj.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {

    //根据当前用户名,和菜品名或套餐名找ShoppingCar对象
    ShoppingCart findBySC(ShoppingCart shoppingCart);

    //插入新的对象到表中
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer save(ShoppingCart shoppingCart);

    //给同个对象更新数量
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    Integer updateNumber(ShoppingCart shoppingCart);

    //根据用户user_id找所有商品
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findAllByUser(Long userId);
    //清空指定用户id的购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    Integer deleteAll(Long userId);
}
